package com.aha.dataanalyzeandview.config;

import org.springframework.context.annotation.Configuration;
import org.springframework.messaging.simp.config.MessageBrokerRegistry;
import org.springframework.web.socket.config.annotation.EnableWebSocketMessageBroker;
import org.springframework.web.socket.config.annotation.StompEndpointRegistry;
import org.springframework.web.socket.config.annotation.WebSocketMessageBrokerConfigurer;

@Configuration
@EnableWebSocketMessageBroker
public class WebSocketConfig implements WebSocketMessageBrokerConfigurer {
    /**
     * 配置信息代理
     */
    @Override
    public void configureMessageBroker(MessageBrokerRegistry config) {
        //订阅Broker名称
        config.enableSimpleBroker("/topic");
        //全局使用消息前缀
        config.setApplicationDestinationPrefixes("/aaa");
    }

    /**
     *注册stomp端点
     */
    @Override
    public void registerStompEndpoints(StompEndpointRegistry registry) {
        //允许使用socketJs方式访问，访问点为KpiWebsocket,允许跨域。
        registry.addEndpoint("/dgs").withSockJS();
    }

}
